package com.motherchild.admin.controller;
import com.motherchild.admin.service.LoginService;
import com.motherchild.common.ApiResponse;
import com.motherchild.admin.dto.LoginDTO;
import com.motherchild.user.dto.Employee;
import com.motherchild.user.dto.User;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author zhuchenxu
 * @create 2025-02-12-10:15
 */
@RestController
@RequestMapping("/auth")
@Slf4j
public class LoginController {

        @Autowired
        private LoginService loginService;


        @PostMapping("/login")
        public ApiResponse<Object> login(@RequestBody LoginDTO loginDTO) {
            Integer token = 1;
            try {
                 token = loginService.login(loginDTO);

            }catch (Exception e){
                e.printStackTrace();
            }
            return ApiResponse.success(token);
        }

        @PostMapping("/fetchUserRole")
        public ApiResponse<Employee> fetchUserRole(@RequestBody LoginDTO loginDTO) {
            Employee token = loginService.fetchUserRole(loginDTO);
            return ApiResponse.success(token);
        }

}
